Fix up CPU allocation and topology reporting.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 24 Feb 2006 18:16:52 +0000 (19:16 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 24 Feb 2006 18:16:52 +0000 (19:16 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/x86/dom0_ops.c
xen/arch/x86/setup.c
xen/common/dom0_ops.c

index 69fcb76aefe6908e71b8b232e73e7bf9d7441ead..3ca142ad692e1426d01ca7ef27ca52b15d2a0a9d 100644 (file)
@@ -181,10 +181,13 @@ long arch_do_dom0_op(struct dom0_op *op, struct dom0_op *u_dom0_op)
     {
         dom0_physinfo_t *pi = &op->u.physinfo;
 
-        pi->threads_per_core = smp_num_siblings;
-        pi->cores_per_socket = boot_cpu_data.x86_max_cores;
+        pi->threads_per_core =
+            cpus_weight(cpu_sibling_map[0]);
+        pi->cores_per_socket =
+            cpus_weight(cpu_core_map[0]) / pi->threads_per_core;
         pi->sockets_per_node = 
-            num_online_cpus() / (pi->threads_per_core * pi->cores_per_socket);
+            num_online_cpus() / cpus_weight(cpu_core_map[0]);
+
         pi->nr_nodes         = 1;
         pi->total_pages      = total_pages;
         pi->free_pages       = avail_domheap_pages();
index 18c8f6be5166767f1721f4d6c85837315a2bbf33..58c143d8a17013aeab1e1b1da4996559cca82bf7 100644 (file)
@@ -437,11 +437,7 @@ void __init __start_xen(multiboot_info_t *mbi)
         set_in_cr4(X86_CR4_OSXMMEXCPT);
 
     if ( opt_nosmp )
-    {
         max_cpus = 0;
-        smp_num_siblings = 1;
-        boot_cpu_data.x86_max_cores = 1;
-    }
 
     smp_prepare_cpus(max_cpus);
 
index 340b667459df7e16e2c823e43d3adfb7db6f588b..003a47b62056849e702069c7958289d5a19c402c 100644 (file)
@@ -165,6 +165,7 @@ long do_dom0_op(struct dom0_op *u_dom0_op)
         domid_t        dom;
         struct vcpu   *v;
         unsigned int   i, cnt[NR_CPUS] = { 0 };
+        cpumask_t      cpu_exclude_map;
         static domid_t rover = 0;
 
         dom = op->u.createdomain.domain;
@@ -195,18 +196,29 @@ long do_dom0_op(struct dom0_op *u_dom0_op)
         read_lock(&domlist_lock);
         for_each_domain ( d )
             for_each_vcpu ( d, v )
-                cnt[v->processor]++;
+                if ( !test_bit(_VCPUF_down, &v->vcpu_flags) )
+                    cnt[v->processor]++;
         read_unlock(&domlist_lock);
         
         /*
-         * If we're on a HT system, we only use the first HT for dom0, other 
-         * domains will all share the second HT of each CPU. Since dom0 is on 
-         * CPU 0, we favour high numbered CPUs in the event of a tie.
+         * If we're on a HT system, we only auto-allocate to a non-primary HT.
+         * We favour high numbered CPUs in the event of a tie.
          */
-        pro = smp_num_siblings - 1;
-        for ( i = pro; i < num_online_cpus(); i += smp_num_siblings )
+        pro = first_cpu(cpu_sibling_map[0]);
+        if ( cpus_weight(cpu_sibling_map[0]) > 1 )
+            pro = next_cpu(pro, cpu_sibling_map[0]);
+        cpu_exclude_map = cpu_sibling_map[0];
+        for_each_online_cpu ( i )
+        {
+            if ( cpu_isset(i, cpu_exclude_map) )
+                continue;
+            if ( (i == first_cpu(cpu_sibling_map[i])) &&
+                 (cpus_weight(cpu_sibling_map[i]) > 1) )
+                continue;
+            cpus_or(cpu_exclude_map, cpu_exclude_map, cpu_sibling_map[i]);
             if ( cnt[i] <= cnt[pro] )
                 pro = i;
+        }
 
         ret = -ENOMEM;
         if ( (d = domain_create(dom, pro)) == NULL )